import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/net/response/use_request/new_goods_list_data.dart';

import '../../model/use_request/use_request_model.dart';
import 'add_use_request_view_model.dart';

class NewChooseGoodsViewModel extends BaseListViewModel<NewGoodsListData> {
  String searchWords = "";

  NewChooseGoodsViewModel(BuildContext context) : super(context);

  dynamic get donate => selectDonate?.pickId??null;
  dynamic get fixedAssets => selectFixedAssets?.pickId??null;
  var model = UseRequestModel();

  PickerDataWithIdModel? selectDonate;
  PickerDataWithIdModel? selectFixedAssets;

  void selectFix(){
    var items = [
      PickerDataWithIdModel(pickId: "",pickName: "全部"),
      PickerDataWithIdModel(pickId: "1",pickName: "是"),
      PickerDataWithIdModel(pickId: "0",pickName: "否"),
    ];

    DataPickerView(context, items,currentFirstData: selectFixedAssets,onSubmitListener: (p1,p2,p3){
      selectFixedAssets = items[p1];
      notifyListeners();
      requestRefresh();
    }).show();
  }
  void selectDo(){
    var items = [
      PickerDataWithIdModel(pickId: "",pickName: "全部"),
      PickerDataWithIdModel(pickId: "1",pickName: "是"),
      PickerDataWithIdModel(pickId: "0",pickName: "否"),
    ];

    DataPickerView(context, items,currentFirstData: selectDonate,onSubmitListener: (p1,p2,p3){
      selectDonate = items[p1];
      notifyListeners();
      requestRefresh();
    }).show();
  }


  @override
  Future<List<NewGoodsListData>> requestListData() async {
    return await model.newGoodsList(
        fixedAssets: fixedAssets, donate: donate, page: page, rows: pageLength,materialNameNoLike: searchWords);
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }
}

extension GoodsEx on NewGoodsListData {
  SelectGoodsInfo toSelectData() {
    return SelectGoodsInfo(
        name: this.materialName,
        unit: this.unit,
        id: this.id,
        total: this.remainingQuantity);
  }

  Map toSubmitInfo(String officeId) {
    // var map =  this.toJson();
    // map['officeId'] = officeId;
    // return map;
    return {
      "materialId": this.materialId,
      "receiptId": this.id,
      "materialName": this.materialName,
      "materialType": this.materialType,
      "brand": brand,
      "model": model,
      "specification": specification,
      "attatchId": attatchId,
      "path": path,
      "unit": unit,
      "quantity": selectNumber,
      "officeId": officeId,
      "remark":remark,
      "materialNo":materialNo,
      "assetType":assetType,
      "donate":donate

    };
  }
}